#include "GLPickNumberOfPlayersScene.h"

#include <iostream>
#include <string>

#include "GLSceneOrthogonalMode.h"
#include "GLSceneInterfaceDrawers.h"

namespace catan
{

GLPickNumberOfPlayersScene::GLPickNumberOfPlayersScene(GameState &gameState, SDLCanvas &sdlCanvas, GLTextures &glTextures, GameMap &gameMap): gameStateRef(&gameState), sdlCanvasRef(&sdlCanvas), glTexturesRef(&glTextures), gameMapRef(&gameMap)
{
}

void GLPickNumberOfPlayersScene::poll()
{
	SDL_Event *keyDownEvent = gameStateRef->pollKeyDownEvent();
	if (keyDownEvent != NULL)
	{
		switch (keyDownEvent->key.keysym.sym)
		{
			case SDLK_2:
				gameStateRef->setNumberOfPlayers(2);
				gameStateRef->nextScreen();
				break;
			case SDLK_3:
				gameStateRef->setNumberOfPlayers(3);
				gameStateRef->nextScreen();
				break;
			case SDLK_4:
				gameStateRef->setNumberOfPlayers(4);
				gameStateRef->nextScreen();
				break;
			default:
				break;
		}
	}
}

void GLPickNumberOfPlayersScene::draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	GLSceneOrthogonalMode::begin(*sdlCanvasRef);
		GLSceneInterfaceDrawers::drawRectangularTexture(0.2f, 0.8f, 0.175f + 0.6f/3, 0.175f, glTexturesRef->getLogoTexture(), *sdlCanvasRef);
		std::string output = "Type a number of players (2-4)";
		GLSceneInterfaceDrawers::drawText(output.c_str(), output.length(), false, 0.675f*(3.0f/4), 0.5f-(0.03f*(32.0f/66)*(output.length()/2.0f)), 0.03f, glTexturesRef->getTextWithBlackBackgroundTexture(), *sdlCanvasRef);
	GLSceneOrthogonalMode::end();
    SDL_GL_SwapBuffers();
}

}
